﻿using System.IO;
using System.Xml.Serialization;
using Microsoft.Xna.Framework.Content.Pipeline;

namespace XNADota.ContentPipeline.Terrain
{
    [ContentImporter(".xml", DefaultProcessor = "LandscapeProcessor", DisplayName = "Landscape Importer")]
    class LandscapeImporter : ContentImporter<LandscapeConfigContent>
    {
        public override LandscapeConfigContent Import(string filename, ContentImporterContext context)
        {
            bool isToSerialize = false;

            if (isToSerialize)
            {
                using (FileStream file = new FileStream(filename, FileMode.Create))
                {
                    new XmlSerializer(typeof(LandscapeConfigContent)).Serialize(file, new LandscapeConfigContent());
                } 
            }
            else
            {
                using (FileStream file = new FileStream(filename, FileMode.Open))
                {
                    LandscapeConfigContent config = (LandscapeConfigContent)new XmlSerializer(typeof(LandscapeConfigContent)).Deserialize(file);
                    return config;
                }
            }
            return new LandscapeConfigContent();
        }
    }
}